package it.massetti.scoponescientifico.game;

import java.util.ArrayList;
import java.util.List;

public class Ground {
	
	private List<Card> cards = new ArrayList<Card>();
	private Team lastTeamCatch;

	/**
	 * Adds a card in the ground cards
	 * @param card
	 */
	public void addCard(Card card) {
		cards.add(card);
	}
	
	/**
	 * Gets a card given a suit and a number
	 * @param suit
	 * @param number
	 * @return card
	 * @throws noCardException
	 */
	public Card getCard (Suit suit, Number number) throws noCardException {
		for (Card current : cards) {
			if(current.suit==suit && current.number==number) {
				return current;
			}
		}
		throw new noCardException();
	}
	
	/**
	 * Take all cards from the ground and return them
	 */
	public void clearGround() {
		cards.clear();
	}
	
	/**
	 * Get the cards
	 * @return cards
	 */
	public List<Card> getCards() {
		return cards;
	}

	/**
	 * Remove the selected cards from the ground
	 * @param cards2
	 * @return cards
	 * @throws noCardException 
	 */
	public void removeCards(List<Card> cardsToGet) throws noCardException {
		if(cards.containsAll(cardsToGet)) {
			cards.removeAll(cardsToGet);
		} else {
			throw new noCardException ();
		}
	}

	/**
	 * Get last Team who catched
	 * @return
	 */
	public Team getLastTeamCatch() {
		return lastTeamCatch;
	}

	/**
	 * Set las Team that catched
	 * @param lastTeamCatch
	 */
	public void setLastTeamCatch(Team lastTeamCatch) {
		this.lastTeamCatch = lastTeamCatch;
	}
}
